package cn.demo.service1;

import cn.demo.service1.entity.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
 * @Author: liujiahao
 * @Description:
 */
@SpringBootApplication(scanBasePackages = "cn.demo.service1")
@EnableFeignClients
@EnableWebMvc
@EnableEurekaClient
@EnableCircuitBreaker
@EnableResourceServer
@EnableBinding(Sink.class)
public class ApplicationService1 {

    public static void main(String[] args) {
        SpringApplication.run(ApplicationService1.class, args);
    }

    /**
     * 不知道为啥需要自己注册一下这个东西，要不访问回调url出错
     *
     * @return
     */
    @Bean
    @Primary
    public DefaultOAuth2ClientContext defaultOAuth2ClientContext() {
        return new DefaultOAuth2ClientContext();
    }

    @StreamListener(Sink.INPUT)
    public void accept(User user){
        System.out.println("接受到的消息"+user);
    }
}
